/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sample.entity.com;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author NgoanTT
 */
@Stateless
public class AccountSessionBean implements AccountSessionBeanRemote, AccountSessionBeanLocal {
    @PersistenceContext(unitName = "Nong_Nghiep-ejbPU")
    private EntityManager em;

    public void persist(Object object) {
        em.persist(object);
    }

    public boolean checkLogin(String username, String password) {
        String url = "SELECT t FROM TblAccount t WHERE t.username = :username and t.password = :password";
        Query query = em.createQuery(url);
        query.setParameter("username", username);
        query.setParameter("password", password);
        List result = query.getResultList();

        if(result.size()>0){
            return true;
        }
        return false;

    }

    public boolean insert(String account_ID, String username, String password, String lastname,
            boolean isAdmin, boolean users, String address, String city, String introduction,
            int age, String genre) {
        TblAccount account = new TblAccount(account_ID, username, password);
        account.setLastname(lastname);
        account.setIsAdmin(isAdmin);
        account.setUsers(users);
        account.setAddress(address);
        account.setCity(city);
        account.setIntroduction(introduction);
        account.setAge(age);
        account.setGenre(genre);
        em.persist(account);
        return true;
    }

    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
 
}
